<?php
	$group = $dsfm_common->get_all("common_group");
	

	$all_data = $dsfm_common->get_all("assessment", "year=".$_SESSION['year']);

	foreach($all_data as $k => $v){
		$total[$v['gid']] += $v['evaluation'];
		$section[$v['gid']] += 1;
	}

	foreach($group as $k => $v){
		if($section[$k+1] != 0){
			$average = $total[$k+1] / $section[$k+1];
			if($average == 0){
				$group[$k]['average'] = 0;
				$group[$k]['result'] = grade($group[$k]['average']);
			}else{
				$group[$k]['average'] = number_format($average, 2);
				$group[$k]['result'] = grade($group[$k]['average']);
			}
		}else{
			$group[$k]['average'] = 0;
			$group[$k]['result'] = grade($group[$k]['average']);
		}
	}

	$tpl->assign("group", $group);
	if($mode=="preview"){
		$tpl->draw("summary-point-preview");
	}else{
		$tpl->draw("summary-point");
	}

	function grade($point){
		if($point <= 2){
			return "ยังไม่ได้คุณภาพ";
		}elseif($point <= 3){
			return "ระดับพอใช้";
		}elseif($point <= 4){
			return "ระดับดี";
		}else{
			return "ระดับดีมาก";
		}
	}
?>